#include "servicemanager.h"
#include "vfsmonitor.h"
#include "fileevent.pb.h"
#include "serviceadaptor.h"

#include <QCoreApplication>

#include <QDBusConnection>

#include <QThread>
#include <QTextStream>
#include <QMetaType>

#include <QDebug>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    qRegisterMetaType<uint32_t>("uint32_t");
    qRegisterMetaType<uint64_t>("uint64_t");
    qRegisterMetaType<std::string>("std::string");

    QThread t2;
    ServiceManager mgr;
    ServiceAdaptor adaptor(&mgr);
    mgr.moveToThread(&t2);
    QThread t;
    VFSMonitor monitor;
    monitor.moveToThread(&t);
    QObject::connect(&t, &QThread::started, &monitor, &VFSMonitor::startMonitor);
    QObject::connect(&t2, &QThread::started, &mgr, &ServiceManager::initSystemBus);
    QObject::connect(&monitor, &VFSMonitor::mountEvent, &mgr, &ServiceManager::handleMountEvent);
    QObject::connect(&monitor, &VFSMonitor::fileEvent, &mgr, &ServiceManager::handleFileEventV2);
    t.start();
    t2.start();

    return a.exec();
}
